
package kaizone.haining.chaobohui.widget;

import kaizone.haining.chaobohui.R;
import kaizone.haining.chaobohui.util.ImageFetcher;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.TextView;

public class DetailGridImage extends FrameLayout {

    private TextView mLevelView;

    private TextView mDescriptionView;

    private RoundAngleImageView mImageView;

    public DetailGridImage(Context context) {
        super(context);
        init();
    }

    public DetailGridImage(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    private void init() {
        // setPadding(10, 10, 5, 9);
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        mLevelView = (TextView) findViewById(R.id.tv01);
        mDescriptionView = (TextView) findViewById(R.id.tv02);
        mImageView = (RoundAngleImageView) findViewById(R.id.img);
        Log.e("DetailGridImage", "onFinishInflate .");
    }

    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        super.onLayout(changed, left, top, right, bottom);
        Log.e("DetailGridImage", "onLayout ..chaned" + changed + ", left=" + left + ", top=" + top
                + ", right=" + right + ", bottom" + bottom);
        mImageView.setScaleType(ScaleType.CENTER_CROP);
        // int width = this.getMeasuredWidth();
        // int height = width * 2 / 3;
        // mImageView.setLayoutParams(new FrameLayout.LayoutParams(width,
        // height));
        // Log.e("DetailGridImage", "imageview.w=" + mImageView.getWidth() +
        // ",imageview.h="
        // + mImageView.getHeight() + ",imageview.mw=" +
        // mImageView.getMeasuredWidth()
        // + ",imageview.mh=" + mImageView.getMeasuredHeight());
    }

    public void setLevel(String level) {
        mLevelView.setText(level);
    }

    public void setDescription(String description) {
        mDescriptionView.setText(description);
    }

    public void setImagePath(String path) {
        // setBackgroundResource(R.drawable.z_z_2);
        mImageView.setImageResource(R.drawable.z_z_2);
    }

    public void loadImage(String path, ImageFetcher imageFetcher) {
        imageFetcher.loadImage(path, mImageView);
    }

}
